﻿using strange.extensions.command.impl;
using strange.extensions.context.api;
using strange.extensions.dispatcher.eventdispatcher.api;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class RequestScoreCommand : EventCommand {

    [Inject]
    public IScoreService scoreService { get; set; }



    public override void Execute()
    {
        Retain();//让这个对象不销毁(等待调用Complete)

        //添加监听
        scoreService.dispatcher.AddListener(Demo1ServiceEvent.RequestScore, OnComplete);
        //请求分数(这个是异步的，请求需要时间)
        scoreService.RequestScore("http://xxxxxx");
    }

    private void OnComplete(IEvent evt)
    {
        Debug.Log("得到参数" + evt.data);
        //移除监听（调用完了）
        scoreService.dispatcher.RemoveListener(Demo1ServiceEvent.RequestScore, OnComplete);

        dispatcher.Dispatch(Demo1MediatorEvent.ScoreChange, evt.data);

        //这个函数被调用，才会被销毁
        Release();
    }
}
